package com.ruoyi.volunteer.venue.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.volunteer.venue.domain.VoluntaryVenue;
import com.ruoyi.volunteer.venue.service.IVoluntaryVenueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务场所Controller
 * 
 * @author ruoyi
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/volunteer/venue")
public class VoluntaryVenueController extends BaseController
{
    @Autowired
    private IVoluntaryVenueService voluntaryVenueService;

    /**
     * 查询服务场所列表
     */
//    @PreAuthorize("@ss.hasPermi('volunteer:venue:list')")
    @GetMapping("/list")
    public TableDataInfo list(VoluntaryVenue voluntaryVenue)
    {
        startPage();
        List<VoluntaryVenue> list = voluntaryVenueService.selectVoluntaryVenueList(voluntaryVenue);
        return getDataTable(list);
    }

    /**
     * 导出服务场所列表
     */
    @PreAuthorize("@ss.hasPermi('volunteer:venue:export')")
    @Log(title = "服务场所", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoluntaryVenue voluntaryVenue)
    {
        List<VoluntaryVenue> list = voluntaryVenueService.selectVoluntaryVenueList(voluntaryVenue);
        ExcelUtil<VoluntaryVenue> util = new ExcelUtil<VoluntaryVenue>(VoluntaryVenue.class);
        util.exportExcel(response, list, "服务场所数据");
    }

    /**
     * 获取服务场所详细信息
     */
    @PreAuthorize("@ss.hasPermi('volunteer:venue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(voluntaryVenueService.selectVoluntaryVenueById(id));
    }

    /**
     * 新增服务场所
     */
    @PreAuthorize("@ss.hasPermi('volunteer:venue:add')")
    @Log(title = "服务场所", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoluntaryVenue voluntaryVenue)
    {
        return toAjax(voluntaryVenueService.insertVoluntaryVenue(voluntaryVenue));
    }

    /**
     * 修改服务场所
     */
    @PreAuthorize("@ss.hasPermi('volunteer:venue:edit')")
    @Log(title = "服务场所", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoluntaryVenue voluntaryVenue)
    {
        return toAjax(voluntaryVenueService.updateVoluntaryVenue(voluntaryVenue));
    }

    /**
     * 删除服务场所
     */
    @PreAuthorize("@ss.hasPermi('volunteer:venue:remove')")
    @Log(title = "服务场所", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(voluntaryVenueService.deleteVoluntaryVenueByIds(ids));
    }
}
